/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_FILE_TYPE_UTIL_H
#define IMAGE_KNIFE_C_FILE_TYPE_UTIL_H

#include "imageknife_task.h"
#include <map>
#include <cstdint>
#include <vector>

namespace ImageKnifePro {

// 文件类型工具类
class FileTypeUtil {
public:
    // 判断文件是否为图像，并返回具体的图片类型
    static ImageFormat CheckImageFormat(const uint8_t* data, size_t length);
    static std::string ImageFormatToString(ImageFormat imageFormat);
    static ImageFormat StringToImageFormat(std::string formatInfo);
private:
    static std::map<ImageFormat, std::vector<std::vector<uint8_t>>>& GetFileSignatureMap();

    // 获取文件类型
    static ImageFormat GetFileType(const uint8_t* data, size_t length);

    // 检查文件头部魔数是否匹配
    static bool MatchesSignature(const uint8_t* data, size_t length, const std::vector<uint8_t>& signature,
                                 ImageFormat fileType);
};
}
#endif // IMAGE_KNIFE_C_FILE_TYPE_UTIL_H
